package momo.app.comms.monitor;

import java.util.Random;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class TestTaskMonitorApp {
	
	private static final Log log = LogFactory.getLog(TestTaskMonitorApp.class);
	
	private static Runnable spawnThread() {
		Thread runTask = new Thread() {
			public void run() {
				Random rand = new Random();
				int taskID = rand.nextInt();
				log.debug("Thread running: " + taskID );
				int counter = 3;
				while (counter > 0) {
//					log.debug("I am still running: " + taskID);
					counter --;
					try {
						sleep(3000);
					} catch (InterruptedException e) {
						log.error("InterruptedException", e);
					}
				}
			}
		};
		return runTask;
	}
	
	public static void main(String args[]) {
		log.debug("Start TaskApp");
		
		TaskMonitor monitor = new TaskMonitor();
		monitor.putTask( spawnThread() );
		monitor.putTask( spawnThread() );
		monitor.putTask( spawnThread() );
	}
}
